home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / VIEWS.ZIP;1 / CVDZIP.EXE / CVHOW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-15  |  4.1 KB  |  181 lines

  1. /*
  2.     cvhow.cpp
  3.  
  4.     "How-does-it-work" window
  5.     
  6.     C++/Views 2.0 Demo
  7.     Copyright (c) 1992, by Liant Software Corp.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12. */
  13.  
  14. #include "cvhow.h"
  15. #include "cvdemovw.h"
  16. #include "editbox.h"
  17. #include "font.h"
  18. #include "pushbttn.h"
  19. #include "messengr.h"
  20. #include "file.h"
  21. #include "tofmstrm.h"
  22. #include "notifier.h"
  23.  
  24. defineClass(HowView, VDialog)
  25.  
  26. HowView::HowView()
  27. {
  28.     ;
  29. }
  30.  
  31. HowView::HowView(VWindow *parent, char *tpc, char *src)
  32.     :    VDialog(5, 30, 300, 180, parent, StyleTitle | StyleCloseBox),
  33.         overviewName(tpc),
  34.         sourceName(src)
  35. {
  36.     if (src) {
  37.         setTitle("How it works");
  38.     }
  39.     else {
  40.         setTitle("How to Order C++/Views");
  41.     }
  42.  
  43.     sourceFont = new VFont("Courier New", 10);
  44.     overviewFont = new VFont("New Times Roman", 12, TRUE);
  45.  
  46.     /* create ok, overview, and source buttons */
  47.     overbttn = 0;
  48.     srcbttn = 0;
  49.     VPushButton *okbttn = 0;
  50.     VPushButton *aboutbttn = 0;
  51.  
  52.     okbttn = new VPushButton(VFrame(25, 10, 80, 30), this, StyleDefaultButton, "Ok");
  53.     setDefButton(okbttn);
  54.     okbttn->uponClick(this, methodOf(VDialog, ok));
  55.  
  56.     /* if src is NULL, don't create Overview and Source buttons */
  57.     if (src) {
  58.         overbttn = new VPushButton(VFrame(130, 10, 80, 30), this, StyleDefaultButton, "Overview");
  59.         overbttn->uponClick(this, methodOf(HowView, overviewBtn));
  60.  
  61.         srcbttn = new VPushButton(VFrame(235, 10, 80, 30), this, StyleDefaultButton, "Source");
  62.         srcbttn->uponClick(this, methodOf(HowView, sourceBtn));
  63.  
  64.         /* enable Source button, disable Overview button */
  65.         srcbttn->enable(TRUE);
  66.         overbttn->enable(FALSE);
  67.  
  68.         if (sourceName != "cvhow.cpp") {
  69.             /* don't show "about" button for About How About box */
  70.             aboutbttn = new VPushButton(VFrame(340, 10, 80, 30), this, StyleDefaultButton, "About");
  71.             aboutbttn->uponClick(this, methodOf(HowView, aboutBtn));
  72.         }
  73.     }
  74.  
  75.     /* create a edit box to display info text */
  76.     msgBox = new VEditBox(VFrame(0.04F, 0.15F, 0.92F, 0.8F), this,
  77.                 StyleBorder | StyleVertical | StyleWordWrap | StyleReadOnly);
  78.  
  79.     msgBox->putText(cvTextFile->getMessage(overviewName).gets());
  80.     msgBox->takeFocus();
  81.     msgBox->setTabs(3);
  82.     msgBox->setFont(overviewFont);
  83. }
  84.  
  85. HowView::~HowView()
  86. {
  87.     delete overviewFont;
  88.     delete sourceFont;
  89. }
  90.  
  91. boolean HowView::free()
  92. {
  93.     delete this;
  94.     return(TRUE);
  95. }
  96.  
  97. boolean HowView::overviewBtn(VButton *b)
  98. /*
  99.     "Overview" button pressed
  100. */
  101. {
  102.     /* enable Source button, disable Overview button */
  103.     srcbttn->enable(TRUE);
  104.     overbttn->enable(FALSE);
  105.  
  106.     /* destroy the msgBox, create a new one with wordWrap */
  107.     delete msgBox;
  108.  
  109.     msgBox = new VEditBox(VFrame(0.04F, 0.15F, 0.92F, 0.8F), this,
  110.             StyleBorder | StyleVertical | StyleWordWrap | StyleReadOnly);
  111.     msgBox->setFont(overviewFont);
  112.     msgBox->putText(cvTextFile->getMessage(overviewName).gets());
  113.     msgBox->setTabs(3);
  114.  
  115.     return(TRUE);
  116. }
  117.  
  118. boolean HowView::sourceBtn(VButton *b)
  119. /*
  120.     "Source" button pressed
  121. */
  122. {
  123.     /* disable Source button, enable Overview button */
  124.     srcbttn->enable(FALSE);
  125.     overbttn->enable(TRUE);
  126.  
  127.     /* destroy the msgBox, create a new one with no wordWrap */
  128.     delete msgBox;
  129.  
  130.     msgBox = new VEditBox(VFrame(0.04F, 0.15F, 0.92F, 0.8F), this,
  131.             StyleBorder | StyleVertical | StyleHorizontal | StyleReadOnly);
  132.  
  133.     msgBox->setFont(sourceFont);
  134.     msgBox->setTabs(3);
  135.     msgBox->update();
  136.  
  137.     /* open and read the source file */
  138.     notifier->beginWait();
  139.  
  140.     VFile    sourceFile(sourceName);
  141.  
  142.     if (!sourceFile.open(ReadOnly)) {
  143.         msgBox->putText("Unable to find source file.");
  144.     }
  145.     else {
  146.         VToFromStream    tofrom;
  147.         VStream            buf;
  148.         
  149.         /* read file into buf using VToFromStream */
  150.         tofrom.beginScan(&sourceFile, &buf);
  151.         tofrom.skipTo(0);
  152.  
  153.         /* copy text into msgBox */
  154.         msgBox->putText(buf.gets());
  155.  
  156.         sourceFile.close();
  157.     }
  158.  
  159.     notifier->endWait();
  160.  
  161.     return(TRUE);
  162. }
  163.  
  164.  
  165. boolean HowView::aboutBtn(VButton *b)
  166. /*
  167.     "About" button pressed
  168. */
  169. {
  170.     /* Display a message using the HowView object */
  171.     HowView    how(this, "How:About", "cvhow.cpp");
  172.  
  173.     /* make the how view visible */
  174.     how.show();
  175.  
  176.     /* activate the dialog (as a modal dialog) */
  177.     how.modal();
  178.  
  179.     return(TRUE);
  180. }
  181.